package com.agung.wonogirimaps.adapter;

import java.util.List;

import com.agung.wonogirimaps.R;
import com.agung.wonogirimaps.entity.Hotel;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class HotelAdapter extends BaseAdapter
{
	static class ViewHolder
	{
		TextView	nama;
		TextView	alamat;
		TextView	kelas;
	}

	private List<Hotel>		listHotel;
	private LayoutInflater	mInflater;

	public HotelAdapter(Context context, List<Hotel> listHotel)
	{
		mInflater = LayoutInflater.from(context);
		this.listHotel = listHotel;
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		return listHotel.size();
	}

	@Override
	public Object getItem(int arg0)
	{
		// TODO Auto-generated method stub
		return listHotel.get(arg0);
	}

	@Override
	public long getItemId(int arg0)
	{
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		ViewHolder holder;
		// cek apakah convertview masih kosong
		if (convertView == null)
		{
			// jika iya maka inisialisasi item2 di single custom listview
			convertView = mInflater.inflate(R.layout.single_list_hotel, null);

			holder = new ViewHolder();
			holder.alamat = (TextView) convertView
					.findViewById(R.id.txt_list_hotel_alamat);
			holder.kelas = (TextView) convertView
					.findViewById(R.id.txt_list_hotel_kelas);
			holder.nama = (TextView) convertView
					.findViewById(R.id.txt_list_hotel_nama);

			// set tag convertview
			convertView.setTag(holder);
		} else
		{
			// jika tidak kosong maka ambil tag
			holder = (ViewHolder) convertView.getTag();
		}

		// set resource nama, alamat, dan gambar,
		// untuk gambar menggunakan imageloader
		holder.alamat.setText(listHotel.get(position).getAlamat());
		holder.kelas.setText(listHotel.get(position).getKelas());
		holder.nama.setText(listHotel.get(position).getNama());
		return convertView;
	}
}
